//
//  LHCollectDetailViewController.m
//  Knight_Tour
//
//  Created by dlios on 15-5-15.
//  Copyright (c) 2015年 TouchOne. All rights reserved.
//

#import "LHCollectDetailViewController.h"
#import "LHCollectDetailUserView.h"
#import "MyNavgationView.h"
#import "LHRecommendTourNotesDetailViewController.h"

@interface LHCollectDetailViewController ()<jumpToDetailNotesDelegate>

@property (nonatomic, retain) NSMutableArray *notesArr;

@end

@implementation LHCollectDetailViewController

- (void)dealloc
{
    [_notesArr release];
    [super dealloc];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.notesArr = [NSMutableArray array];
    self.navigationController.navigationBar.hidden = YES;
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self getManagerWithCover];
    [self createCollectDetailView];
    [self createNavigation];
    
    
}
- (void)createNavigation
{
    MyNavgationView *myNV = [[MyNavgationView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
    
    self.navigationController.navigationBar.translucent = NO;
    [myNV creatTitle:@"我的游记"];
    
    myNV.leftTarget = self;
    myNV.leftAction = @selector(backToUser);
    [myNV creatLeftButtonWithImage:@"btn_nav_back"];
    
    [self.view addSubview:myNV];
    [myNV release];
}
- (void)createCollectDetailView
{
    LHCollectDetailUserView *CDUV = [[LHCollectDetailUserView alloc] initWithFrame:CGRectMake(0, 64, LHWidth, LHheight - 64)];
    
    CDUV.notesArr_str = _notesArr;
    
    CDUV.delegate = self;
    
    [self.view addSubview:CDUV];
    [CDUV release];
    
}

// 实现协议方法
- (void)jumpToDetailNotesWithIndexPath:(NSIndexPath *)indexPath
{
    LHRecommendTourNotesDetailViewController *reTour = [[[LHRecommendTourNotesDetailViewController alloc] init] autorelease];
    
    reTour.notesDetailArr = [_notesArr[indexPath.row] mutableCopy];
    
    reTour.notesName = [[_notesArr[indexPath.row] firstObject] name];
    
    [self.navigationController pushViewController:reTour animated:YES];
    
}


// 解档
-(void) getManagerWithCover
{
    NSString *path = [[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"LHRecommendTourNotes"] stringByAppendingPathComponent:@"LHRecommendTourNotes.kk"];
    self.notesArr = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
}



- (void)backToUser
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
